What is pascal-case?
The pascal-case npm package is used to convert strings into PascalCase format, where the first letter of each word is capitalized and all words are concatenated without spaces. This is often used in programming to name classes, types, and other identifiers that require this specific casing convention.
What are pascal-case's main functionalities?
Convert string to PascalCase
This feature takes a string and converts it to PascalCase. The given code sample demonstrates how you might manually convert a string to PascalCase by splitting it into words, capitalizing the first letter of each word, and then joining them together without spaces.
"hello world".split(' ').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join('')
Other packages similar to pascal-case
camelcase
The camelcase package converts strings to camelCase. It is similar to pascal-case but the first letter of the result is in lowercase, which is the standard for naming variables and functions in many programming languages.
change-case
The change-case package is a more comprehensive string transformation library that includes pascalCase among many other case transformations. It provides a suite of utilities for various case conversions, making it more versatile than pascal-case if multiple case conversion functions are needed.
uppercamelcase
The uppercamelcase package is another alternative that converts strings to UpperCamelCase (or PascalCase). It is very similar to pascal-case but might have different handling of edge cases or additional options.
Pascal Case
Pascal case a string. Explicitly adds a single underscore between groups of numbers to keep readability (E.g. 1.20.5
becomes 1_20_5
, not 1205
).
Supports Unicode (non-ASCII characters) and non-string entities, such as objects with a toString
property, numbers and booleans. Empty values (null
and undefined
) will result in an empty string.
Installation
npm install pascal-case --save
Usage
var pascalCase = require('pascal-case')
pascalCase('string')
pascalCase('camelCase')
pascalCase('sentence case')
pascalCase('MY STRING', 'tr')
Typings
Includes a TypeScript definition.
License
MIT